<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" type="text/css" href="<%=path %>/static/css/css.css?1" />
<link rel="stylesheet" type="text/css" href="<%=path %>/static/jquery-ui/jquery-ui.min.css" />
<script type="text/javascript" src="<%=path %>/static/js/json2.js"></script>
<script type="text/javascript" src="<%=path %>/static/js/jquery.js"></script>
<script type="text/javascript" src="<%=path %>/static/jquery-ui/jquery-ui.min.js"></script>
<script type="text/javascript" src="<%=path %>/static/layer/layer.js"></script>
<script type="text/javascript" src="<%=path %>/static/js/gridview.js?v=1"></script>
<script type="text/javascript" src="<%=path %>/static/js/formview.js?v=1"></script>
<script type="text/javascript" src="<%=path %>/static/js/tool.js"></script>
<script type="text/javascript" src="<%=path %>/static/js/validate.js"></script>
<script type="text/javascript" src="<%=path %>/wechat/js/copy/ZeroClipboard.js"></script>
<SCRIPT type="text/javascript">
    $.ajaxSetup({
       async: false
    });
    <!--
	var gridSetting = {
			id:'qhtaskGrid',
			po:"QhTask",
			title:'',
			height:'auto',
			service:"uiServices!listSimple",
			tbId:"TaskTb",
			pageInfo: {
				records: 12,//auto表示根据容器高度自动判断
				orderby : "id desc"
			},
			oper:{
                isDisplay:true,
            	operName:"",
            	url:"",
            	cssClass:"Operation",
            	width:80
            },
			fields:[
			   {	name:'id',
					hide:true
			   },{
                    name: 'id',
                    descs:"ID",
                    align:'center',
                    thstyle:"width:60px"
               },
               {
				   name: 'title',
				   descs:"标题",
				   align:'left'
			   },{
                   name: 'shareCnt',
                   descs:"分享量",
                   align:'center',
                   thstyle:"width:100px"
               }
			   ,{
				   name: 'readCnt',
				   descs:"点击量",
				   align:'center',
				   thstyle:"width:100px"
			   }
			   ,{
               	   name: 'clickRate',
               	   descs:"点击率%",
               	   align:'center',
               	   thstyle:"width:100px"
               }
               ,{
                   name: 'spend',
                   descs:"花费",
                   align:'center',
                   thstyle:"width:100px"
               }
               ,{
                   name: 'operState',
                   descs:"暂停/启动",
                   align:'center',
                   thstyle:"width:100px"
               }
               ,{
                   name: 'state',
                   descs:"状态",
                   type:'state',
                   staval:{'99':'未审核','1':'审核通过','-2':'审核不通过','2':'分享中','-1':'已结束'},
                   thstyle:"width:80px",
                   align:'center'
               }
               ,{
                   name: 'investAmount',
                   descs:"限额",
                   align:'center',
                   thstyle:"width:80px"
               }
			]
		};
	var grid,form0;
    $(document).ready(function(){
    	grid = new GridView("list",gridSetting,"list");
		grid.init();
		var data = [];
		if("${sessionScope.userInfo.type}"=="B"){
		    data.push({r:"=",name:'createUser',value:"${sessionScope.userInfo.id}"});
		}

		grid.load({data:data});

		ajustHeight();

		$("#deleteBtn").click(function(){
		   grid.deletes("deleteMappedRoleNavis",function(ret){
              if(ret==-1){
                 layer.msg("删除失败，请重试！");
              }else{
                 layer.msg("删除" + ret.recordNum + "条记录！",function(ret){
                    grid.reload();
                 });
              }
           });
		});
    });

    //-->
</SCRIPT>
</head>

<body>
<ul class=tab_nav>
  <li>
    <a class="current" href="javascript:void(0)">投放计划</a>
  </li>
  <li id="tab_nav_add">
    <a href="/qh/public/common/r2.htmls?page=task/task_edit">新建计划</a>
  </li>
</ul>
<div class="contrainer">
<div class="rcon2" >
<table class="search_tb">
   <tr>
      <td>
         <select name="type" style="width:100px;display:none">
            <option value="">类型</option>
            <option value="新手任务">新手任务</option>
            <option value="普通任务">普通任务</option>
         </select>
      </td>
      <td style="padding-left:15px;">
         <select name="state" style="width:120px;">
            <option value="">状态</option>
            <option value="99">未审核</option>
            <option value="1">审核通过</option>
            <option value="-2">审核不通过</option>
            <option value="2">分享中</option>
            <option value="-1">已结束</option>
         </select>
      </td>
      <td style="display:none"><input type="text" name="id" placeholder="ID" /></td>
      <td style="display:none"><input type="text" name="title" placeholder="任务标题" /></td>
      <td>
         <input class="cssTime" type="text" onclick="WdatePicker()" name="effectTime" placeholder="开始时间" />-<input class="cssTime" type="text" onclick="WdatePicker()" name="effectTime" placeholder="结束时间" />
      </td>
      <td>
         <input type="text" name="adver" placeholder="广告主" style="float:left;" />
         <input type="button" class="searchbtn" value="" id="queryBtn">
         <input type="button" class="btnblue" value="删除" id="deleteBtn">
         <input type="button" class="btnblue" value="暂停" onclick="editState(-1)" >
         <input type="button" class="btnblue" value="启动" onclick="editState(1)" >
      </td>
   </tr>
</table>
</div>
<div id="list" class="rbox2"></div>
</div>
<div id="alertBox_user" style="display:none">
   <form id="formedit">
      <table class="ctable">
         <tr>
            <td style="width:100px;text-align:right">最高收益：</td>
            <td>
               <input type="text" style="width:280px;" datatype="Money" msg="请输入格式正确的最高收益！" id="txtCommission" placeholder="请输入格式正确的最高收益" />
            </td>
         </tr>
         <tr>
            <td style="text-align:right">实际最高收益：</td>
            <td>
               <input type="text" style="width:280px;" datatype="Money" msg="请输入格式正确的实际最高收益！" id="txtRealCommission" placeholder="请输入格式正确的实际最高收益" />
            </td>
         </tr>
         <tr>
            <td style="text-align:right">分享收益：</td>
            <td>
               <input type="text" style="width:280px;" datatype="Money" msg="请输入格式正确的分享收益！" id="txtShareProfit" placeholder="请输入格式正确的分享收益" />
            </td>
         </tr>
         <tr>
            <td style="text-align:right">阅读收益：</td>
            <td>
               <input type="text" style="width:280px;" datatype="Money" msg="请输入格式正确的阅读收益！" id="txtReadProfit" placeholder="请输入格式正确的阅读收益" />
            </td>
         </tr>
      </table>
   </form>
</div>
<script type="text/javascript" src="<%=path %>/static/js/underscore.js"></script>
<script type='text/javascript' src='<%=path %>/static/My97DatePicker/WdatePicker.js'></script>
<script type='text/javascript' src='<%=path %>/dwr/engine.js'></script>
<script type='text/javascript' src='<%=path %>/dwr/util.js'></script>
<script type='text/javascript' src='<%=path %>/dwr/interface/BaseDwr.js'></script>
<script>
    $("#queryBtn").click(function(){
       var id = $(".search_tb").find(":input[name=id]").val();
       var Title = $(".search_tb").find(":input[name=title]").val();
       var adver = $(".search_tb").find(":input[name=adver]").val();
       var effectTime1 = $(".search_tb").find(":input[name=effectTime]:eq(0)").val();
       var effectTime2 = $(".search_tb").find(":input[name=effectTime]:eq(1)").val();
       var state = $(".search_tb").find(":input[name=state]").val();
       var type = $(".search_tb").find(":input[name=type]").val();
       var data = [];
       if(id!==""){
          data.push({r:"=",name:'id',value:id});
       }
       if(Title!==""){
          data.push({r:"like",name:'title',value:"%"+Title+"%"});
       }
       if(adver!==""){
          data.push({r:"like",name:'adver',value:"%"+adver+"%"});
       }
       if(effectTime1!==""){
          data.push({r:">=",name:'effectTime',value:effectTime1});
       }
       if(effectTime2!==""){
          data.push({r:"<=",name:'effectTime',value:effectTime2});
       }
       if(state!==""){
          data.push({r:"=",name:'state',value:state});
       }
       if(type!==""){
          data.push({r:"=",name:'type',value:type});
       }

       grid.load({data:data});
       ajustHeight();
    });
    function afterLoad_TaskTb(){
       $(".rcon2 .mtable tbody tr").each(function(){
          var id=$(this).attr("recordid");
          var type='${sessionScope.userInfo.type}';
          var html="";
          html+="<a href=<%=path %>/public/common/r2.htmls?page=task/task_edit&id="+id+" >编辑</a>";
          var state=$(this).find("td[name=state]").attr("staval");
          if(state!=-1&&state!=99){
             var oper_html="<a href='javascript:end("+id+",-1)'><img src='<%=path %>/static/images/start.png' /></a>";
             $(this).find("td[name=operState]").html(oper_html);
          }
          if(type=="A"&&state==99){
             html+="<a href=javascript:audit("+id+") style='margin-left:6px;' >审核</a>";
          }
          $(this).find(".Operation").html(html);

          if(state==-1){
             var oper_html="<a href='javascript:end("+id+",1)'><img src='<%=path %>/static/images/end.png' /></a>";
             $(this).find("td[name=operState]").html(oper_html);
          }

          $uid=$(this).find("td[name=adver]");

          $.getJSON(g_path+"/public/common/getAdverName.htmls",{uid:$uid.text()},function(data){
             $uid.text(data.name);
          });

          $shareCnt=$(this).find("td[name=shareCnt]");
          $readCnt=$(this).find("td[name=readCnt]");
          $clickRate=$(this).find("td[name=clickRate]");
          $spend=$(this).find("td[name=spend]");
          $.getJSON(g_path+"/public/common/getTaskShareById.htmls",{id:id},function(data){
             $shareCnt.text(data.sharecnt);
             $readCnt.text(data.readcnt);
             var per;
             if(data.sharecnt==0){
                per="0%";
             }
             else{
                per=data.readcnt/data.sharecnt;
                per=(per*100).toFixed(2);
             }
             $clickRate.text(per);
             $spend.text(data.spend);
          });

          html="<a href=<%=path %>/public/common/r2.htmls?page=task/task_view&id="+id+">"+$(this).find("td[name=title]").text()+"</a>";
          $(this).find("td[name=title]").html(html);
       });

    }
    function end(id,state){
       $.getJSON(g_path+"/public/common/taskStateEdit.htmls",{id:id,state:state},function(data){
          if(data.state==1){
             layer.alert("操作成功！");
             grid.reload();
          }
          else{
             layer.msg("投放金额不能大于账户余额！");
          }
       });
    }

    if('${sessionScope.userInfo.type}'=="A"){
       $("#tab_nav_add").hide();
    }

    function editState(state){
       var chk_value="";
       $('input[name="_rowbox"]:checked').each(function(){
           chk_value+=$(this).parent().parent().attr("recordid")+",";
       });
       chk_value=trim(chk_value);
       $.getJSON(g_path+"/public/common/taskStateEditByIds.htmls",{ids:chk_value,state:state},function(data){
          if(data.num>0){
             grid.reload();
          }
       });
    }
    function audit(id){
       layer.open({
          title : "审核",
          type : 1,
          skin : 'layui-layer-rim', // 加上边框
          area : [ '500px', '330px' ], // 宽高
          content : $("#alertBox_user"),
          btn : [ "确认","关闭" ],
          yes : function(index, layero) {
             if(!Validator.Validate(document.getElementById('formedit'),0)){
             	return;
             }
             $.getJSON(g_path+"/public/common/setCommission.htmls",{id:id,Commission:$("#txtCommission").val(),RealCommission:$("#txtRealCommission").val(),ShareProfit:$("#txtShareProfit").val(),ReadProfit:$("#txtReadProfit").val()},function(data){
                layer.alert("审核成功！");
                grid.load();
                layer.close(index);
             });
          },
          end : function(ret) {
          }
       });
    }

</script>
</body>
</html>